package com.seek.tuana.lab;

import android.graphics.drawable.AnimationDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.widget.ImageView;



public class MyAnimationThread extends Thread {
	
	private boolean checkrepeat=true;
	private AnimationDrawable myani;
	private int totalFrame = 0;
	private int count = 0;
	private int time=100;
	private int customtime=0;
	private ImageView img;
	
	
	public boolean isCheckrepeat() {
		return checkrepeat;
	}

	public void setCheckrepeat(boolean checkrepeat) {
		this.checkrepeat = checkrepeat;
	}



	public int getCustomtime() {
		return customtime;
	}

	public void setCustomtime(int customtime) {
		this.customtime = customtime;
	}

	
	public MyAnimationThread(AnimationDrawable imageView, ImageView img){
		myani = imageView;
		totalFrame  = imageView.getNumberOfFrames();
		this.img = img;
		
		
	}

	@Override
	public void run() {
		while(checkrepeat){
			try {
				if(count>=totalFrame)
					count = 0;
				img.setBackgroundDrawable(myani.getFrame(count));
				Log.i("TA", "Frame " + count);
				sleep(200);
				Log.i("TA", time/10*((customtime==0)?1:customtime)+" Sleep");
			} catch (InterruptedException e) {
				Log.i("TA", e.getMessage().toString());
			}
			count++;
		}
		
	}
	
	
}
